/**
 * 
 */
package de.guidoludwig.jtm.client.artists;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import com.jgoodies.binding.beans.BeanAdapter;
import com.jgoodies.binding.value.ValueHolder;
import com.jgoodies.binding.value.ValueModel;

import de.guidoludwig.af.AbstractHomeModel;
import de.guidoludwig.jtm.domain.Artist;
import de.guidoludwig.jtm.server.AbstractRepository;
import de.guidoludwig.jtm.server.ArtistRepository;

/**
 * @author guido
 * 
 */
public class ArtistHomeModel extends AbstractHomeModel<Artist> {

	private static ArtistHomeModel INSTANCE;

	private final ValueModel selectionHTMLModel;

	public ArtistHomeModel() {
		super();
		selectionHTMLModel = new ValueHolder(null, true);
		getSelectionAdapter().addPropertyChangeListener(
				BeanAdapter.PROPERTYNAME_BEAN, new PropertyChangeListener() {
					@Override
					public void propertyChange(PropertyChangeEvent evt) {
						selectionHTMLModel.setValue(ArtistHTMLFormat.INSTANCE
								.format(getSelectionAdapter().getBean()));
					}
				});
		selectionHTMLModel.setValue(ArtistHTMLFormat.INSTANCE
				.format(getSelectionAdapter().getBean()));
	}
	
	public ValueModel getSelectionHTMLModel() {
		return selectionHTMLModel;
	}

	public static ArtistHomeModel getInstance() {
		if (INSTANCE == null) {
			INSTANCE = new ArtistHomeModel();
		}
		return INSTANCE;
	}

	@Override
	protected AbstractRepository<Artist> getRepository() throws Exception {
		return new ArtistRepository();
	}

}
